package net.huashitong.ssydt.provider.exam.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.huashitong.ssydt.PaginationResult;
import net.huashitong.ssydt.exam.entity.SsExamPaperProduce;
import net.huashitong.ssydt.exam.entity.vo.SsExamPaperProduceQueryVO;
import net.huashitong.ssydt.provider.exam.service.SsExamPaperProduceService;
import net.huashitong.ssydt.provider.utils.StringUtils;
import net.huashitong.ssydt.provider.web.model.Result;
import net.huashitong.ssydt.provider.web.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.10.11
 */
@Api(value = "/exam/paper/produce", tags = {"试卷生产表管理（后台）"})
@RestController
@RequestMapping("/exam/paper/produce")
public class SsExamPaperProduceController {

    private SsExamPaperProduceService ssExamPaperProduceService;

    @Autowired
    public SsExamPaperProduceController(SsExamPaperProduceService ssExamPaperProduceService) {
        this.ssExamPaperProduceService = ssExamPaperProduceService;
    }


    @ApiOperation(value = "分页查询列表", notes = "分页查询列表")
    @GetMapping
    public Result<PaginationResult<SsExamPaperProduce>> getList(@ModelAttribute SsExamPaperProduceQueryVO queryVO) {
        PaginationResult<SsExamPaperProduce> result = ssExamPaperProduceService.paginationQuery(queryVO);
        return ResultUtils.getSuccessResults(result);
    }

    @ApiOperation(value = "查询单条记录", notes = "查询单条记录")
    @GetMapping("/{id}")
    public Result<SsExamPaperProduce> get(@PathVariable Long id) {
        SsExamPaperProduce ssExamPaperProduce = ssExamPaperProduceService.selectByPrimaryKey(id);
        return ResultUtils.getSuccessResults(ssExamPaperProduce);
    }

    @ApiOperation(value = "新增试卷生产记录", notes = "新增试卷生产记录")
    @PostMapping
    public Result<String> post(@RequestBody SsExamPaperProduce ssExamPaperProduce) {
        if (StringUtils.isBlank(ssExamPaperProduce.getTopics())) {
            ssExamPaperProduce.setTopics("");
        }
        ssExamPaperProduceService.insertSelective(ssExamPaperProduce);
        return ResultUtils.getSuccessResults();
    }

    @ApiOperation(value = "修改生产记录", notes = "修改生产记录")
    @PutMapping("/{id}")
    public Result<String> put(@PathVariable Long id, @RequestBody SsExamPaperProduce ssExamPaperProduce) {
        ssExamPaperProduce.setId(id);
        if (StringUtils.isBlank(ssExamPaperProduce.getTopics())) {
            ssExamPaperProduce.setTopics("");
        }
        ssExamPaperProduceService.updateByPrimaryKey(ssExamPaperProduce);
        return ResultUtils.getSuccessResults();
    }


    @ApiOperation(value = "删除记录", notes = "删除记录")
    @DeleteMapping("/{id}")
    public Result<String> delete(@PathVariable Long id) {
        ssExamPaperProduceService.deleteByPrimaryKey(id);
        return ResultUtils.getSuccessResults();
    }

    @ApiOperation(value = "生产试卷", notes = "生产试卷")
    @PutMapping("/{id}/produce-paper")
    public Result<String> putProducePaper(@PathVariable Long id) {
        ssExamPaperProduceService.putProducePaper(id);
        return ResultUtils.getSuccessResults();
    }


}
